home *** CD-ROM | disk | FTP | other *** search
/ The Sunday Times: The Month 2004 August / The Sunday Times - The Month 2004-08.iso / pc / engine / modules / tracks.swf / scripts / frame_1 / DoAction.as
Encoding:
Text File  |  2004-07-02  |  11.5 KB  |  433 lines

  1. function loadImage(mc, node, extrapath)
  2. {
  3.    var _loc3_ = extrapath;
  4.    if(_loc3_ == null)
  5.    {
  6.       _loc3_ = "";
  7.    }
  8.    var strDefaultPath = Tardis.ASSETS_FOLDER + "images/" + Tardis.ActiveSection.id + "/";
  9.    var _loc1_ = node.firstChild.nodeValue;
  10.    var _loc2_ = node.attributes.path;
  11.    if(_loc2_ != null)
  12.    {
  13.       _loc1_ = _loc2_ + _loc1_;
  14.    }
  15.    else
  16.    {
  17.       _loc1_ = strDefaultPath + _loc3_ + _loc1_;
  18.    }
  19.    if(strPathPrefix == null)
  20.    {
  21.       strPathPrefix = "";
  22.    }
  23.    mc.loadMovie(strPathPrefix + _loc1_);
  24. }
  25. function addLink(mc)
  26. {
  27.    Links[mc.link] = mc;
  28. }
  29. function getMCfromLink(Item)
  30. {
  31.    var _loc1_ = Item;
  32.    if(Links[_loc1_] == null)
  33.    {
  34.       var _loc2_ = [];
  35.       while(_loc1_ != sideMenu.ItemHome)
  36.       {
  37.          _loc2_.unshift(_loc1_._name.split("_").pop());
  38.          _loc1_ = _loc1_._parent._parent;
  39.       }
  40.       var _loc3_ = _loc2_.join("/");
  41.       Links[_loc1_] = Links[_loc3_];
  42.    }
  43.    return Links[_loc1_];
  44. }
  45. function removeLinkListener()
  46. {
  47.    Tardis.sideMenu.EB.removeListener(this);
  48. }
  49. function init()
  50. {
  51.    build();
  52.    _visible = true;
  53.    trackUp(mc_t_1);
  54. }
  55. function interrupt()
  56. {
  57.    fade(this.snd,0,55);
  58.    mc_controls.gotoAndStop("paused");
  59. }
  60. function resume()
  61. {
  62.    snd.setVolume(55);
  63. }
  64. function build()
  65. {
  66.    var strID = Tardis.ActiveSection.id;
  67.    var Colors = Tardis.Colors;
  68.    strColor = Colors.getString(strID);
  69.    strColor2 = Colors.getString(strID + "50");
  70.    SECTION_COLOR = Colors.getHex(strID);
  71.    SECTION_COLOR50 = Colors.getHex(strID + "50");
  72.    DEFAULT_COLOR = Colors.getHex("default");
  73.    DEFAULT_COLOR50 = Colors.getHex("default50");
  74.    defaultColor = new Color(bodyLinkMC.arrowMC);
  75.    defaultColor.setRGB(SECTION_COLOR50);
  76.    var ndbuttons = nodeData.byName("buttons");
  77.    txtListenTo.htmlText = ndbuttons.byName("listen").getText();
  78.    txtListenTo.textColor = SECTION_COLOR;
  79.    txtListenTo.resize = "left";
  80.    loadImage(mc_cover,nodeData.byName("image"));
  81.    var ndTracks = nodeData.byName("tracks");
  82.    strTrackpath = Tardis.ASSETS_FOLDER + ndTracks.attributes.path;
  83.    var ndBodyLink = nodeData.byName("link");
  84.    if(ndBodyLink.byName("label").getText() != null)
  85.    {
  86.       animatedLink = false;
  87.       bodyLinkMC.printable = false;
  88.       bodyLinkMC.contentFF.htmlText = ndBodyLink.byName("label").getText();
  89.       bodyLinkMC.contentFF.textColor = SECTION_COLOR50;
  90.       var arwColor = new Color("bodyLinkMC.arrowMC.arwHolder");
  91.       bodyLinkMC.arrowMC.arwColor.setRGB(SECTION_COLOR50);
  92.       bodyLinkMC.link = ndBodyLink.attributes.link;
  93.       bodyLinkMC.navLink = true;
  94.       bodyLinkMC.contentFF.autoSize = true;
  95.       bodyLinkMC.btn._width = bodyLinkMC.contentFF._width + bodyLinkMC.arrowMC._x - 20;
  96.       bodyLinkMC.arrowMC._x = bodyLinkMC.contentFF._x + bodyLinkMC.contentFF._width + 1;
  97.       bodyLinkMC.mAnimatedLink._visible = false;
  98.    }
  99.    else if(ndBodyLink.byName("label_animated").getText() != null)
  100.    {
  101.       animatedLink = true;
  102.       bodyLinkMC.printable = false;
  103.       var arrLabels = ndBodyLink.byName("label_animated").getText().split("|");
  104.       bodyLinkMC.arrowMC._visible = false;
  105.       bodyLinkMC.mAnimatedLink.bigText = arrLabels[0];
  106.       bodyLinkMC.mAnimatedLink.smallText = arrLabels[1];
  107.       bodyLinkMC.mAnimatedLink.linkColor = SECTION_COLOR50;
  108.       bodyLinkMC.mAnimatedLink._visible = true;
  109.       bodyLinkMC.link = ndBodyLink.attributes.link;
  110.       bodyLinkMC.navLink = true;
  111.       bodyLinkMC.btn._width = bodyLinkMC.contentFF._width + bodyLinkMC.arrowMC._x - 20;
  112.    }
  113.    else
  114.    {
  115.       bodyLinkMC.arrowMC._visible = false;
  116.       bodyLinkMC._y = 385;
  117.       bodyLinkMC._height = 0;
  118.       bodyLinkMC._visible = false;
  119.       bodyLinkMC.btn.enabled = false;
  120.    }
  121.    arrTracks = [];
  122.    arrClips = [];
  123.    var ndTrack;
  124.    var strClip;
  125.    var objClip;
  126.    var n = 0;
  127.    while(n < ndTracks.childNodes.length)
  128.    {
  129.       ndTrack = ndTracks.childNodes[n];
  130.       arrTracks.push(ndTrack.attributes.file);
  131.       attachMovie("trackListingMC","mc_t_" + (n + 1),++depth);
  132.       objClip = eval("mc_t_" + (n + 1));
  133.       objClip._x = 9;
  134.       if(ndTrack.byName("title").getText() != null)
  135.       {
  136.          objClip.anim_mc._visible = false;
  137.          objClip.titleHolderMC.titleFF.htmlText = ndTrack.byName("title").getText();
  138.          objClip.titleHolderMC.titleFF.textColor = DEFAULT_COLOR50;
  139.          objClip.titleHolderMC.titleFF.relead();
  140.       }
  141.       else
  142.       {
  143.          var arrLabels = ndTrack.byName("title_animated").getText().split("|");
  144.          objClip.anim_mc.mBuyOnlineText.contentFF.htmlText = arrLabels[0];
  145.          objClip.anim_mc.mBuyOnlineText2.contentFF.htmlText = arrLabels[1];
  146.          objClip.anim_mc.mBuyOnlineText.contentFF.textColor = DEFAULT_COLOR50;
  147.          objClip.anim_mc.mBuyOnlineText2.contentFF.textColor = DEFAULT_COLOR50;
  148.          objClip.titleHolderMC._visible = false;
  149.       }
  150.       objClip._y = TRACKS_POS;
  151.       TRACKS_POS += objClip._height;
  152.       arrClips.push(objClip);
  153.       n++;
  154.    }
  155.    arrayPos = 0;
  156.    currentTrack = arrClips[arrayPos];
  157. }
  158. function soundComplete()
  159. {
  160.    var _loc1_ = false;
  161.    arrayPos++;
  162.    if(arrayPos == arrClips.length)
  163.    {
  164.       if(arrClips.length <= 2)
  165.       {
  166.          _loc1_ = true;
  167.       }
  168.       else
  169.       {
  170.          arrayPos = 0;
  171.       }
  172.    }
  173.    if(_loc1_)
  174.    {
  175.       snd.stop();
  176.       mc_timebar.setHandle(0);
  177.    }
  178.    else
  179.    {
  180.       currentTrack = arrClips[arrayPos];
  181.       trackUp(currentTrack);
  182.    }
  183.    mc_controls.gotoAndStop("standby");
  184. }
  185. function soundRewind()
  186. {
  187.    snd.stop();
  188.    snd.start(0);
  189. }
  190. function soundPlay()
  191. {
  192.    createEmptyMovieClip("track_sound",++depth);
  193.    snd = new Sound(track_sound);
  194.    snd.setVolume(55);
  195.    snd.onSoundComplete = function()
  196.    {
  197.       soundComplete();
  198.    };
  199.    snd.onLoad = function()
  200.    {
  201.       this.start();
  202.    };
  203.    var _loc1_ = strTrackpath + arrTracks[nmTrackNum - 1] + ".mp3";
  204.    snd.loadSound(_loc1_,false);
  205.    mc_timebar.play();
  206. }
  207. function soundResume(posToStart)
  208. {
  209.    var _loc1_ = posToStart;
  210.    if(_loc1_ == null)
  211.    {
  212.       sndPos = snd.position / 1000;
  213.    }
  214.    else
  215.    {
  216.       nmPos = _loc1_;
  217.    }
  218.    if(_loc1_ == 0)
  219.    {
  220.       trackUp(currentTrack);
  221.    }
  222.    else
  223.    {
  224.       snd.start(nmPos,1);
  225.    }
  226.    mc_controls.gotoAndStop("active");
  227. }
  228. function soundPause()
  229. {
  230.    snd.stop();
  231. }
  232. function soundStop()
  233. {
  234.    snd.stop();
  235.    delete snd;
  236.    mc_sound.removeMovieClip();
  237. }
  238. function trackOver(obj)
  239. {
  240.    obj.gotoAndStop("over");
  241. }
  242. function trackOut(obj)
  243. {
  244.    obj.gotoAndStop("off");
  245. }
  246. function trackUp(obj)
  247. {
  248.    var _loc1_ = obj;
  249.    if(nmTrackNum > 0)
  250.    {
  251.       trackOut(this["mc_t_" + nmTrackNum]);
  252.    }
  253.    currentTrack = _loc1_;
  254.    nmTrackNum = parseInt(_loc1_._name.split("_")[2]);
  255.    arrayPos = nmTrackNum - 1;
  256.    soundStop();
  257.    soundPlay();
  258.    _loc1_.gotoAndStop("on");
  259. }
  260. function txtOver(mc)
  261. {
  262.    var _loc1_ = mc;
  263.    _loc1_.gotoAndStop("over");
  264.    Tardis.sideMenu.doOver(_loc1_.link);
  265.    if(_loc1_ == bodyLinkMC)
  266.    {
  267.       if(animatedLink)
  268.       {
  269.          bodyLinkMC.mAnimatedLink.mBuyOnlineText.txtLabel.textColor = SECTION_COLOR;
  270.          bodyLinkMC.mAnimatedLink.mBuyOnlineText2.contentFF.textColor = SECTION_COLOR;
  271.          bodyLinkMC.mAnimatedLink.mBuyOnlineText.arrowMC.gotoAndStop("on");
  272.       }
  273.       else
  274.       {
  275.          bodyLinkMC.arrowMC.gotoAndStop("on");
  276.          bodyLinkMC.contentFF.textColor = SECTION_COLOR;
  277.       }
  278.    }
  279. }
  280. function txtOut(mc)
  281. {
  282.    var _loc1_ = mc;
  283.    _loc1_.gotoAndStop("off");
  284.    Tardis.sideMenu.doOut(_loc1_.link);
  285.    if(_loc1_ == bodyLinkMC)
  286.    {
  287.       if(animatedLink)
  288.       {
  289.          bodyLinkMC.mAnimatedLink.mBuyOnlineText.txtLabel.textColor = SECTION_COLOR50;
  290.          bodyLinkMC.mAnimatedLink.mBuyOnlineText2.contentFF.textColor = SECTION_COLOR50;
  291.          bodyLinkMC.mAnimatedLink.mBuyOnlineText.arrowMC.gotoAndStop("off");
  292.       }
  293.       else
  294.       {
  295.          bodyLinkMC.arrowMC.gotoAndStop("off");
  296.          bodyLinkMC.contentFF.textColor = SECTION_COLOR50;
  297.       }
  298.    }
  299. }
  300. function txtUp()
  301. {
  302.    if(bodyLinkMC.navLink)
  303.    {
  304.       Tardis.sideMenu.doUp(bodyLinkMC.link);
  305.    }
  306.    else
  307.    {
  308.       Tardis.webPageOpen(bodyLinkMC.link,"_blank");
  309.    }
  310. }
  311. function doOver(num)
  312. {
  313.    if(bodyLinkMC.link == num)
  314.    {
  315.       mc_buy_btn.gotoAndStop("over");
  316.       if(animatedLink)
  317.       {
  318.          bodyLinkMC.mAnimatedLink.mBuyOnlineText.txtLabel.textColor = SECTION_COLOR;
  319.          bodyLinkMC.mAnimatedLink.mBuyOnlineText2.contentFF.textColor = SECTION_COLOR;
  320.          bodyLinkMC.mAnimatedLink.mBuyOnlineText.arrowMC.gotoAndStop("on");
  321.       }
  322.       else
  323.       {
  324.          bodyLinkMC.arrowMC.gotoAndStop("on");
  325.          bodyLinkMC.contentFF.textColor = SECTION_COLOR;
  326.       }
  327.    }
  328. }
  329. function doOut(num)
  330. {
  331.    mc_buy_btn.gotoAndStop("off");
  332.    if(bodyLinkMC.link == num)
  333.    {
  334.       if(animatedLink)
  335.       {
  336.          bodyLinkMC.mAnimatedLink.mBuyOnlineText.txtLabel.textColor = SECTION_COLOR50;
  337.          bodyLinkMC.mAnimatedLink.mBuyOnlineText2.contentFF.textColor = SECTION_COLOR50;
  338.          bodyLinkMC.mAnimatedLink.mBuyOnlineText.arrowMC.gotoAndStop("off");
  339.       }
  340.       else
  341.       {
  342.          bodyLinkMC.arrowMC.gotoAndStop("off");
  343.          bodyLinkMC.contentFF.textColor = SECTION_COLOR50;
  344.       }
  345.    }
  346. }
  347. function startTimebar()
  348. {
  349.    var _loc1_ = this;
  350.    mc_timebar.onEnterFrame = function()
  351.    {
  352.       var _loc1_ = this;
  353.       if(_loc1_.DRAGGING == true)
  354.       {
  355.          var _loc2_ = _loc1_.mc_handle._x / _loc1_.AVAIL_WIDTH;
  356.          var f = Math.round(_loc2_ * _loc1_._parent.snd.duration);
  357.       }
  358.       else if(_loc1_._parent.mc_controls._currentFrame == 20)
  359.       {
  360.          _loc2_ = _loc1_._parent.snd.position / _loc1_._parent.snd.duration;
  361.          if(_loc2_ < 1)
  362.          {
  363.             _loc1_.mc_handle._x = _loc2_ * _loc1_.AVAIL_WIDTH;
  364.          }
  365.       }
  366.    };
  367. }
  368. function clearUp()
  369. {
  370.    mc_timebar.onEnterFrame = null;
  371. }
  372. function setWidth(nm)
  373. {
  374.    mc_timebar.mc_track._width = nm;
  375.    mc_timebar.AVAIL_WIDTH = nm - mc_timebar.mc_handle._width;
  376. }
  377. function setTarget(mc)
  378. {
  379.    mc_timebar.TARGET = mc;
  380. }
  381. Links = {};
  382. Tardis.sideMenu.EB.addListener(this);
  383. _visible = false;
  384. TRACKS_POS = 226;
  385. depth = 0;
  386. this.onUnload = function()
  387. {
  388.    interrupt();
  389.    removeLinkListener();
  390.    this.onUnload = null;
  391. };
  392. TextField.prototype.relead = function()
  393. {
  394.    this.autoSize = true;
  395. };
  396. nmTrackNum = 0;
  397. setTarget(snd);
  398. setWidth(163);
  399. startTimebar();
  400. mc_timebar.mc_handle.btn.onPress = function()
  401. {
  402.    var _loc1_ = this;
  403.    _loc1_._parent.startDrag(false,0,0,_loc1_._parent._parent.AVAIL_WIDTH,0);
  404.    _loc1_._parent._parent.DRAGGING = true;
  405.    _loc1_._parent._parent._parent.soundPause();
  406. };
  407. mc_timebar.mc_handle.btn.onRelease = mc_timebar.mc_handle.btn.onReleaseOutside = function()
  408. {
  409.    var _loc1_ = this;
  410.    _loc1_.posToStart = math.ceil(_loc1_._parent._parent.mc_handle._x / _loc1_._parent._parent.AVAIL_WIDTH * _loc1_._parent._parent._parent.snd.duration / 1000);
  411.    if(_loc1_._parent._parent._parent.mc_controls._currentFrame != 30)
  412.    {
  413.       _loc1_._parent._parent._parent.soundResume(_loc1_.posToStart);
  414.    }
  415.    _loc1_._parent.stopDrag();
  416.    _loc1_._parent._parent.DRAGGING = false;
  417. };
  418. mc_timebar.mc_handle.btn.onRollOver = function()
  419. {
  420.    var _loc1_ = this;
  421.    _loc1_.myColor = new Color(_loc1_._parent.scrubbaMC);
  422.    _loc1_.myColor.setRGB(_loc1_._parent._parent._parent.SECTION_COLOR);
  423. };
  424. mc_timebar.mc_handle.btn.onRollOut = function()
  425. {
  426.    var _loc1_ = this;
  427.    _loc1_.myColor = new Color(_loc1_._parent.scrubbaMC);
  428.    _loc1_.myColor.setRGB(_loc1_._parent._parent._parent.DEFAULT_COLOR);
  429. };
  430. stop();
  431. onReady();
  432. onComplete();
  433.